﻿<from class="layui-form layui-form-pane" action="">
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" autocomplete="off"
                   placeholder="请输入标题" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">目录</label>
        <div class="layui-input-block">
            <select name="catalogId" lay-filter="catalogId" id="catalogId">
            </select>
        </div>
    </div>

    <div class="layui-form-item" style="text-align: center;">
        <button class="layui-btn" lay-submit="" lay-filter="favorite-edit">确认修改</button>
    </div>
</from>
<script type="text/javascript">

    layui.define(['layer', 'form'], function () {
        var form = layui.form;
        var id = workUtils.get("id");

        $.getJSON("../favorite/get/" + id, function (data) {
            $("[name='title']").val(data.title);
            $("[name='id']").val(data.id);
            form.render(); //这个很重要
            $.getJSON("../favorite/listcatalog", function (result) {
                var optionstring = "";
                $.each(result, function (i, item) {
                    optionstring += "<option value=\"" + item.id + "\" >" + item.title + "</option>";
                });
                $("#catalogId").html('<option value=""></option>' + optionstring);
                $("#catalogId").val(data.catalogId);
                form.render('select'); //这个很重要
            });
        });

        form.on('submit(favorite-edit)', function (data) {
            var index = layer.load(1);
            setTimeout(function () {
                workUtils.ajaxPost('../favorite/edit', data.field, function (result) {
                    layer.close(index);
                    workUtils.msg(result);
                });
            }, 400);
            return false;
        });
    });
</script>